﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T_Material.API.Application.CommandHandlers.StatisticsHandlers;
using T_Material.API.Application.Commands.RequisitionCommand;
using T_Material.API.Application.Commands.StatisticsCommand;

namespace T_Material.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = nameof(ApiversionInfo.物资统计))]

    public class StatisticsAPIController : ControllerBase
    {
        private readonly IMediator mediator;
        public StatisticsAPIController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加物资统计
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> StatisticsAdd(StatisticsCreatedCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 删除物资统计
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> StatisticsDelete([FromQuery] StatisticsDeleteCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改物资统计
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> StatisticsUpdate(StatisticsUpdateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 批删物资统计
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> StatisticsDels([FromQuery] StatisticsDelsCommand command)
        {
            try
            {
                return await mediator.Send(command);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
